from appium import webdriver
import time
import random
import threading


def dz_redmi():
    print('红米手机开始调试')
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '9.0'
    desired_caps['deviceName'] = '25452086'
    # desired_caps['appPackage'] = 'com.lbe.security.miui'
    # desired_caps['appActivity'] = 'com.android.packageinstaller.permission.ui.GrantPermissionsActivity'
    desired_caps['appPackage'] = 'com.ss.android.ugc.aweme'
    desired_caps['appActivity'] = '.splash.AliasSplashActivity'
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    for a in range(0,100):
        driver.swipe(700, 1600, 700, 600,500)
        driver.tap([(986, 1412)])
        # driver.tap([(700, 1000)])
        time.sleep(random.randint(3,6))
        print(a)

def dz_huaw():
    print('华为手机开始调试')
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '10.0'
    # desired_caps['deviceName'] = 'CUY0219513000198'
    desired_caps['deviceName'] = '192.168.0.156:5556'
    # desired_caps['appPackage'] = 'com.ss.android.ugc.aweme'
    # desired_caps['appActivity'] = '.splash.SplashActivity'
    desired_caps['appPackage'] = 'com.lbe.security.miui'
    desired_caps['appActivity'] = 'com.android.packageinstaller.permission.ui.GrantPermissionsActivity'
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    for a in range(0,100):
        driver.swipe(700, 1600, 700, 600,500)
        driver.tap([(986, 1412)])
        time.sleep(random.randint(3,6))
        print(a)

def buyu_phone1():
    print('开始捕鱼')
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '10.0'
    desired_caps['deviceName'] = 'CUY0219513000198'
    desired_caps['appPackage'] = 'com.awbydsgl.huawei'
    desired_caps['appActivity'] = '.MainActivity'
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    time.sleep(30)
    print('等待结束')
    while 'true':
        print('点击')
        driver.tap([(986, 989)])



def trymain(fun):
    def tryfun():
        try:
            fun()
        except Exception:
            print('发生异常')
            print(Exception)
            tryfun()
    init(tryfun)

def init(fun):
    name = threading.Thread(target=fun)
    name.start()

# trymain(dz_redmi)
trymain(dz_huaw)
# trymain(buyu_phone1)






